package org.log4jconfig.xml.editor.hyperlink;

import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.ui.PartInitException;

public class JavaElementHyperlink implements IHyperlink {

	private IJavaElement element = null;

	private IRegion hyperlinkRegion = null;

	public JavaElementHyperlink(IRegion hyperlinkRegion, IJavaElement element) {
		this.element = element;
		this.hyperlinkRegion = hyperlinkRegion;
	}

	public IRegion getHyperlinkRegion() {
		return hyperlinkRegion;
	}

	public String getHyperlinkText() {
		return "Jump to " + element.getElementName();
	}

	public String getTypeLabel() {
		return "Jump to " + element.getElementName();
	}

	public void open() {
		try {
			JavaUI.revealInEditor(JavaUI.openInEditor(element), element);
		} catch (PartInitException e) {
		} catch (JavaModelException e) {
		}

	}

}
